#if <%- getApiDefineFlag(api) %>

using System;
using System.Collections.Generic;
using PlayFab.<%- api.name %>Models;
using PlayFab.Internal;
using PlayFab.SharedModels;

namespace PlayFab
{
<%- generateApiSummary("    ", api, "description")
%>    public <%- isPartial %>class PlayFab<%- api.name %>InstanceAPI : IPlayFabInstanceApi
    {
        public readonly PlayFabApiSettings apiSettings = null;
        public readonly PlayFabAuthenticationContext authenticationContext = null;
<% if( api.name === "Admin" || api.name === "Server" ) { %>
        public PlayFab<%- api.name %>InstanceAPI() { }

        public PlayFab<%- api.name %>InstanceAPI(PlayFabApiSettings settings)
        {
            apiSettings = settings;
        }

        public PlayFab<%- api.name %>InstanceAPI(PlayFabAuthenticationContext context)
        {
            authenticationContext = context;
        }

        public PlayFab<%- api.name %>InstanceAPI(PlayFabApiSettings settings, PlayFabAuthenticationContext context)
        {
            apiSettings = settings;
            authenticationContext = context;
        }
<% } else if( api.name === "Client" || api.name === "Authentication" ) { %>
        public PlayFab<%- api.name %>InstanceAPI()
        {
            authenticationContext = new PlayFabAuthenticationContext();
        }

        public PlayFab<%- api.name %>InstanceAPI(PlayFabApiSettings settings)
        {
            apiSettings = settings;
            authenticationContext = new PlayFabAuthenticationContext();
        }

        public PlayFab<%- api.name %>InstanceAPI(PlayFabAuthenticationContext context)
        {
            authenticationContext = context ?? new PlayFabAuthenticationContext();
        }

        public PlayFab<%- api.name %>InstanceAPI(PlayFabApiSettings settings, PlayFabAuthenticationContext context)
        {
            apiSettings = settings;
            authenticationContext = context ?? new PlayFabAuthenticationContext();
        }
<% } else { %>
        public PlayFab<%- api.name %>InstanceAPI(PlayFabAuthenticationContext context)
        {
            if (context == null)
                throw new PlayFabException(PlayFabExceptionCode.AuthContextRequired, "Context cannot be null, create a PlayFabAuthenticationContext for each player in advance, or call <PlayFabClientInstanceAPI>.GetAuthenticationContext()");
            authenticationContext = context;
        }

        public PlayFab<%- api.name %>InstanceAPI(PlayFabApiSettings settings, PlayFabAuthenticationContext context)
        {
            if (context == null)
                throw new PlayFabException(PlayFabExceptionCode.AuthContextRequired, "Context cannot be null, create a PlayFabAuthenticationContext for each player in advance, or call <PlayFabClientInstanceAPI>.GetAuthenticationContext()");
            apiSettings = settings;
            authenticationContext = context;
        }
<% } %><% if (hasClientOptions) { %>
        /// <summary>
        /// Verify client login.
        /// </summary>
        public bool IsClientLoggedIn()
        {
            return authenticationContext == null ? false : authenticationContext.IsClientLoggedIn();
        }
<% } %><% if (hasEntityTokenOptions) { %>
        /// <summary>
        /// Verify entity login.
        /// </summary>
        public bool IsEntityLoggedIn()
        {
            return authenticationContext == null ? false : authenticationContext.IsEntityLoggedIn();
        }
<% } %>
        /// <summary>
        /// Clear the Client SessionToken which allows this Client to call API calls requiring login.
        /// A new/fresh login will be required after calling this.
        /// </summary>
        public void ForgetAllCredentials()
        {
            if (authenticationContext != null)
            {
                authenticationContext.ForgetAllCredentials();
            }
        }
<% for(var i in api.calls) { var apiCall = api.calls[i]; %>
<%- generateApiSummary("        ", apiCall, "summary") %><%- getDeprecationAttribute("        ", apiCall)
%>        public void <%- apiCall.name %>(<%- apiCall.request %> request, Action<<%- apiCall.result %>> resultCallback, Action<PlayFabError> errorCallback, object customData = null, Dictionary<string, string> extraHeaders = null)
        {
            var context = (request == null ? null : request.AuthenticationContext) ?? authenticationContext;
            var callSettings = apiSettings ?? PlayFabSettings.staticSettings;
<%- getRequestActions("            ", apiCall) %>            PlayFabHttp.MakeApiCall("<%- apiCall.url %>", request, <%- getAuthParams(apiCall) %>, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this);
        }<%- getCustomApiFunction("        ", api, apiCall, true) %>
<% } %>
    }
}

#endif
